/**
*	MinimumDistanceSearcher.java 1.0 Jan 13, 2013
*
* Find two neighbouring numbers in an array with the smallest distance to each 
* other. The index of the first number should be outputted to the screen. 
* For example, in the sequence 4 8 6 1 2 9 4 the minimum distance is 1 (between 
* 1 and 2). The function should return the index 3 (of number 1).
* If ecxists more than one decision should be outputted only a first one.
* All input should be get from keyboard
*/

import java.util.*;

public class MinimumDistanceSearcher{
	
	public static void main(String[] args){
		
		boolean inputRequired = true;
		String[] stringArray;
		int[] intArray;
		
		do {
			System.out.println("Enter the array of integers: ");
			Scanner in = new Scanner(System.in);
			String input = in.nextLine();
			inputRequired = false;
			
			stringArray = input.split(" ");
			if (stringArray.length < 2) {
				System.out.println("Array shall include at least 2 elements or more");
				inputRequired = true;
			}
			intArray = new int[stringArray.length];
			for (int i = 0; i < intArray.length; i++){
			
				/*if(){ TBD check that all values are numbers (need regexp)
				}*/
				intArray[i] = Integer.parseInt(stringArray[i]);
			}
		} while (inputRequired);
		
		int index = 0;	
		int distance = Math.abs(intArray[1] - intArray[0]);
		for (int i = 0; i < intArray.length - 1; i++){
			if (distance > Math.abs(intArray[i + 1] - intArray[i])){
				distance = Math.abs(intArray[i + 1] - intArray[i]);
				index = i;
			}
		}
		
		System.out.println("Index of first number of the smallest distance pair is "
			+ index);
	}
}